package com.pachong.android.frameworkbase.customviews.multiviewpager;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.pachong.android.frameworkbase.R;
import com.pachong.android.frameworkbase.imageloader.ImageLoader;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/6/8
 */
public class ImageFragment extends Fragment {
    private View mContentView = null;
    private ImageView ivImage;
    private String mUrl = null;

    static final String GET_PHOTO_DATA = "GetPhotoData";

    public static ImageFragment newInstance(String photoData) {
        return newInstance(photoData, "");
    }

    public static ImageFragment newInstance(String photoData, String filePath) {
        Bundle args = new Bundle();
        ImageFragment fragment = new ImageFragment();
        args.putString(GET_PHOTO_DATA, photoData);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mContentView = LayoutInflater.from(getActivity()).inflate(R.layout.frag_image, null);
        initView(mContentView);
        return mContentView;
    }


    protected void initView(View contentView) {
        ivImage = (ImageView) contentView.findViewById(R.id.iv_image);
        if (getArguments() != null) {
            mUrl = getArguments().getString(GET_PHOTO_DATA);
        } else {
            Log.w("ImageFragment", "Data Not Put");
        }
        ImageLoader.with(getContext())
                .load(mUrl)
                .into(ivImage)
                .start();
    }

}
